﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using WcsZz.Extend;
using wms_wpf.Apiservice;
using wms_wpf.DialogView;
using wms_wpf.Dto;

namespace wms_wpf.ViewModels
{
    public class UserManageViewModel:BindableBase, INavigationAware
    {

        
        public UserManageViewModel() 
        {
            viewService = new ViewService();
            View_UserDtos = new List<View_UserDto>();
           
            GetList_View_UserCommand = new DelegateCommand(GetList_View_User);
            UpdateInfoCommand=new DelegateCommand<string>(UpdateInfo);
            UpdatePassWordCommand = new DelegateCommand<string>(UpdatePassWord);
            UpdateNameCommand = new DelegateCommand<string>(UpdateName);
            RegisterCommand = new DelegateCommand(Register);
            GetList_View_User();
            EventAggregatorHelper.EventAggregator.ResgiterMessage(arg =>
            {
                GetList_View_User();
            }, "GetList_View_User");//选择Setting的消息聚合器
        }
   
        public DelegateCommand GetList_View_UserCommand { get; set; }
        public DelegateCommand<string> UpdateInfoCommand { get; set; }
        public DelegateCommand<string> UpdatePassWordCommand { get; set; }  
        public DelegateCommand<string> UpdateNameCommand { get; set; }
        public DelegateCommand RegisterCommand { get; set; }

        private readonly IViewService viewService;
        private List<View_UserDto> view_UserDtos;
        public List<View_UserDto> View_UserDtos
        {
            get { return view_UserDtos; }
            set { view_UserDtos = value;RaisePropertyChanged();}
        }

        private  async void GetList_View_User()
        {
            View_UserDtos= await  viewService.GetList_View_User();
        }
        private async void UpdateInfo(string obj)
        {
        HandyControl.Controls.Dialog.Show(new Dialog4(obj));
           
        }
        private async void UpdateName(string obj)
        {
            HandyControl.Controls.Dialog.Show(new Dialog5(obj));
        }
        private void UpdatePassWord(string obj) 
        {
            HandyControl.Controls.Dialog.Show(new Dialog6(obj));
        }
        private void Register()
        {
            HandyControl.Controls.Dialog.Show(new Dialog7());
        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            
        }

        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return false;
        }

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
          
        }
    }
}
